#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;

const int N = 300010;
int n, m;
int a[N], s[N];

vector<int> alls;       // 存储位置
vector<PII> add, query; // add为原数组，query为查询数组

int find(int x)
{
	int l = 0, r = alls.size() - 1;
	while (l < r)
	{
		int mid = l + r >> 1;
		if (alls[mid] >= x)
			r = mid;
		else
			l = mid + 1;
	}
	return r + 1;
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) // 存储位置
	{
		int x, c;
		cin >> x >> c;
		add.push_back({ x, c });
		alls.push_back(x);
	}

	for (int i = 0; i < m; i++) // 加入查询
	{
		int l, r;
		cin >> l >> r;
		query.push_back({ l, r });

		alls.push_back(l);
		alls.push_back(r);
	}

	// 排序、去重
	sort(alls.begin(), alls.end());
	alls.erase(unique(alls.begin(), alls.end()), alls.end());

	//Debug
	printf("排序加去重后 alls 的大小为: %d\n", alls.size());
	for (int i = 0; i < alls.size(); i++)
	{
		printf("alls 中存储的下标为: %d", alls[i]);
		printf(", 离散化后的下标为: %d\n", find(alls[i]));
	}

	// 处理加和
	for (auto item : add)
	{
		int x = find(item.first);
		printf("插入位置 %d 离散化后的位置为 %d\n", item.first, x);  //Debug
		a[x] += item.second;
	}

	// 预处理前缀和
	for (int i = 1; i <= alls.size(); i++)
		s[i] = s[i - 1] + a[i];

	//处理询问
	for (auto item : query)
	{
		int l = find(item.first), r = find(item.second);
		 printf("求和左区间 %d 离散化后的下标为 %d,右区间 %d 离散化后的位置为 %d\n", item.first, l, item.second, r);  //Debug
		cout << s[r] - s[l - 1] << endl;
	}
	return 0;
}